package com.skyline.attraction.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.skyline.attraction.dao.AttractionInviteDao;
import com.skyline.attraction.model.AttractionInvitation;
import com.skyline.attraction.service.AttractionInviteService;
import com.skyline.base.type.Activity;
import com.skyline.user.model.Fan;

/**
 * 
 * @author Colonel
 *
 */
@Service("attactionInviteService")
public class AttractionInviteServiceImpl implements AttractionInviteService {

	@Autowired
	private AttractionInviteDao inviteDao;

	@Override
	public long addInvitation(AttractionInvitation invitation) {
		return inviteDao.insertInvitation(invitation.getOwerId(),
				invitation.getFanId(), invitation.getFanNickname(),
				invitation.getFanPortait(), invitation.getSpotId(),
				invitation.getSpotName(), invitation.getContent(),
				invitation.getInvitingTime(), invitation.getAppointmentTime());
	}

	// 注：时间规范性
	@Override
	public long  addInvitation(long owerId, long fanId, String fanNickname,
			String fanPortait, long spotId, String spotName, String content,
			Date appointmentTime) {
		// 得到当前系统时间
		Date invitingTime = new Date();
		return inviteDao.insertInvitation(owerId, fanId, fanNickname, fanPortait,
				spotId, spotName, content, invitingTime, appointmentTime);
	}

	@Override
	public AttractionInvitation getInvitationById(long id) {
		return inviteDao.queryInvitationById(id);
	}

	@Override
	public List<AttractionInvitation> getInvitationsByOwerId(long owerId,
			Activity activity) {
		return inviteDao.queryInvitationByOwerId(owerId, activity);
	}

	@Override
	public List<AttractionInvitation> getInvitationsByFanId(long fanId, Activity activity) {
		return inviteDao.queryInvitationsOfFanByFanId(fanId, activity);
	}

	@Override
	public List<AttractionInvitation> getInvitationsBySpotId(long spotId,
			Activity activity) {
		return inviteDao.queryInvitationsBySpotId(spotId, activity);
	}

	@Override
	public List<Fan> getFansByOwerIdAndTimestamp(long owerId, Date timestamp,
			Activity activity) {
		return inviteDao.queryFansByOwerIdTimestamp(owerId, timestamp, activity);
	}

	@Override
	public void deleteInvitationById(long id) {
		inviteDao.deleteInvitationById(id);
	}

	@Override
	public void deleteInvitationByOwerId(long owerId) {
		inviteDao.deleteInvitationByOwerId(owerId);
	}

	@Override
	public void deleteInvitationByFanId(long fanId) {
		inviteDao.deleteInvitationByFanId(-1, fanId, null);
	}

	@Override
	public void deleteInvitationBySpotId(long spotId) {
		inviteDao.deleteInvitationBySpotId(spotId);
	}

	@Override
	public void deleteInvitationByOwerIdTimestamp(long owerId, Date timestamp) {
		inviteDao.deleteInvitationByTimestamp(owerId, timestamp);
	}

	@Override
	public void deleteAll() {
		inviteDao.deleteAll();
	}

	@Override
	public void updateInvitation(Long owerId, long spotId, String spotName,
			Date timestamp, Date appointmentTime) {
		inviteDao.updateInvitationByOwerIdAndTimestamp(owerId, spotId, spotName, timestamp, appointmentTime);
	}

}
